<template>
  <div>
    <a :href="'/cate/?id='+data.id"><antwork :data="data" /></a>
    <a-input v-model="name1"></a-input>
    <br>
    <select v-model="pid">
      <option v-model="pid" :value="0">主</option>
      <option v-for="i in nr" :value="i.id" :key="i.id">{{i.name}}</option>
    </select>
    <a-button type="primary" @click="add">添加</a-button>
  </div>
</template>

<script>
import axios from 'axios'
import antwork from "./antwork"

export default {
  data() {
    return {
      data:{},
      name1:'',
      nr:[],
      pid:'',
    }
  },
  components:{
    antwork,
  },
  created() {
    this.get_data()
    axios({
      url:"http://127.0.0.1:8000/work/"
    }).then(res =>{
      this.nr = res.data
    })
  },
  methods: {
    add(){
        axios({
          url:'http://127.0.0.1:8000/work/',
          method:'post',
          data:{'name':this.name1,'pid':this.pid}
        }).then(res =>{
          console.log(res.data)
        })
    },
    get_data:function(){
      axios.get("http://127.0.0.1:8000/workorder/").then(res=>{
        console.log(res.data);
        var mytree = {"id":0,name:""};
        mytree['children'] = res.data;
        this.data = mytree
      })
    },
  },
}
</script>

<style>

</style>
